﻿#ifndef _DB_IQUERYFILTER_H
#define _DB_IQUERYFILTER_H

#include "geometry/interface/igeometry.h"
#include "kernel/Referenced.h"
#include "udatabase/dll_cfg.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			namespace Interface
			{
				/// <summary>
				/// 空间关系类型
				/// </summary>
				enum SpatialQueryRelationType
				{
					/// <summary>
					/// 未知关系
					/// </summary>
					SQRT_Unknown                     = 0,
					/// <summary>
					/// 相交
					/// </summary>
					SQRT_Intersects                  = 1,
					/// <summary>
					/// 相触
					/// </summary>
					SQRT_Touches                     = 2,
					/// <summary>
					/// 重叠
					/// </summary>
					SQRT_Overlaps                    = 3,
					/// <summary>
					/// 跨越
					/// </summary>
					SQRT_Cross                     = 4,
					/// <summary>
					/// 被包含
					/// </summary>
					SQRT_Within                      = 5,
					/// <summary>
					/// 包含
					/// </summary>
					SQRT_Contains                    = 6,
					/// <summary>
					/// 包围盒相交
					/// </summary>
					SQRT_EnvelopeIntersects          = 7,
					/// <summary>
					/// 自定义
					/// </summary>
					SQRT_Custom                      = 8
				};

				/// <summary>
				/// 查询模式 
				/// </summary>
				enum QueryModeType
				{
					/// <summary>
					/// 未知模式
					/// </summary>
					QM_Unknown                     = 0,
					/// <summary>
					/// 属性查询
					/// </summary>
					QM_Attribute                   = 1,
					/// <summary>
					/// 空间查询
					/// </summary>
					QM_Spatial                     = 2,
					/// <summary>
					/// 属性和空间查询
					/// </summary>
					QM_AttributeAndSpatial         = 3,
					/// <summary>
					/// 元数据
					/// </summary>
					QM_MetaInfo					   = 4,
					/// <summary>
					/// 所有信息
					/// </summary>
					QM_ALL						   = 7
				};

				/// <summary>
				/// 查询条件，用于设置属性查询和空间查询条件
				/// </summary>
				class FD_DB_Export IQueryFilter : public FD::Kernel::CReferenced
				{
				public:
					/// <summary>
					/// 默认析构函数
					/// </summary>
					virtual ~IQueryFilter();
				public:
					/// <summary>
					/// 获取查询语句中字段名称
					/// 多个字段名称，用","隔离
					/// </summary>
					/// <returns>字段名称</returns>
					virtual String getFieldName() const;
					/// <summary>
					/// 获取查询语句中WhereClause语句
					/// </summary>
					/// <returns>WhereClause语句</returns>
					virtual String getWhereClause() const;
					/// <summary>
					/// 获取查询语句中 Limit限制
					/// </summary>
					/// <returns>Limit限制，默认为0</returns>
					virtual UINT32 getLimitNum() const;
					/// <summary>
					/// 获取查询语句中 Offset限制
					/// </summary>
					/// <returns>Offset限制，默认为0</returns>
					virtual UINT32 getOffsetNum() const;
					/// <summary>
					/// 获取空间查询的几何体
					/// </summary>
					/// <returns>几何体对象，内部引用。</returns>
					virtual const FD::Kernel::Geometry::Interface::IGeometry* getQueryGeometryRef() const;
					/// <summary>
					/// 获取空间查询的空间关系条件
					/// </summary>
					/// <returns>空间关系条件</returns>
					virtual FD::Utility::DB::Interface::SpatialQueryRelationType getSpatialRelation();
					/// <summary>
					/// 获取查询中的查询模式
					/// </summary>
					/// <returns>查询模式</returns>
					virtual FD::Utility::DB::Interface::QueryModeType getQueryMode() const;
					/// <summary>
					/// 设置查询语句中查询字段
					/// </summary>
					/// <param name="names">字段名称，多个字段，用","隔离</param>
					/// <returns></returns>
					virtual void setFieldName(const String& names);
					/// <summary>
					/// 设置查询语句中WhereClause语句
					/// </summary>
					/// <param name="whereclause">WhereClause语句</param>
					/// <returns></returns>
					virtual void setWhereClause(const String& whereclause);
					/// <summary>
					/// 设置查询语句中Limit限制
					/// </summary>
					/// <param name="limit">返回限制</param>
					/// <returns></returns>
					virtual void setLimitNum(UINT32 limit);
					/// <summary>
					/// 设置查询语句中Offset限制
					/// </summary>
					/// <param name="offset">offset值</param>
					/// <returns></returns>
					virtual void setOffsetNum(UINT32 offset);
					/// <summary>
					/// 设置空间查询几何体
					/// </summary>
					/// <param name="geometry">查询几何体</param>
					/// <returns></returns>
					virtual void setQueryGeometry(const FD::Kernel::Geometry::Interface::IGeometry* geometry);
					/// <summary>
					/// 设置查询模式
					/// </summary>
					/// <param name="queryMode">查询模式</param>
					/// <returns></returns>
					virtual void setQueryMode(FD::Utility::DB::Interface::QueryModeType queryMode);
					/// <summary>
					/// 设置空间查询关系
					/// </summary>
					/// <param name="spatialRelType">空间查询关系</param>
					/// <returns></returns>
					virtual void setSpatialRelation(FD::Utility::DB::Interface::SpatialQueryRelationType spatialRelType);
					/// <summary>
					/// 克隆函数
					/// </summary>
					/// <returns>查询对象</returns>
					virtual IQueryFilter * clone() const;

				protected:
					/// <summary>
					/// 默认构造函数
					/// </summary>
					IQueryFilter();
				private:
					C_DISABLE_COPY(IQueryFilter);
				};
			}
		}
	}
}

#endif
